const arrayProto = Array.prototype
export const arrayMethods = Object.create(arrayProto)
const methodsToPatch = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']
methodsToPatch.forEach(function (method) {
  // cache original method
  arrayMethods[method] = function (...args) {
    arrayProto[method].call(this, ...args)
    let insert = null
    switch (method) {
      case 'push':
      case 'unshift':
        insert = args
        break
      case 'splice':
        insert = args.slice(2)
        break
      default:
        break
    }

    const ob = this.__ob__
    //这里需要observeArray方法,所以去Observe里面绑定this
    if (insert) ob.observeArray(insert)
    ob.dep.notify()
  }
})
